package edu.xmut.yuepai.upload.service.impl;


import edu.xmut.yuepai.model.vo.UploadVO;
import edu.xmut.yuepai.upload.service.AsyncUploadService;
import edu.xmut.yuepai.upload.service.UploadService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@Service
public class UploadServiceImpl implements UploadService {

    @Resource
    private AsyncUploadService asyncUploadService;

    @Override
    public UploadVO uploadBlogPicture(MultipartFile multipartFile) {
        UploadVO uploadVO = new UploadVO();
        // 得到图片ID
        long id = System.currentTimeMillis();
        uploadVO.setId(String.valueOf(id));
        // 异步提交上传任务，不关心结果
        asyncUploadService.asyncUploadPictureAndSaveToDB(id, multipartFile);
        // 直接返回图片ID
        return uploadVO;
    }
}
